﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ChatBox.Utilities;

namespace ChatBox.Models
{
  public class ServerInfo : MessageRepository
  {
    #region Constructors

    public ServerInfo()
      : base()
    {
    }

    #endregion

    #region Public Properties

    public String Address
    {
      get
      {
        return _address;
      }
      set
      {
        if ( _address != value )
        {
          _address = value;

          this.OnPropertyChanged( "Address" );
        }
      }
    }

    public ViewableCollection<ChannelInfo> Channels
    {
      get
      {
        return _channels;
      }
    }

    public ChannelInfo CurrentChannel
    {
      get
      {
        return _currentChannel;
      }
      set
      {
        if ( value != _currentChannel )
        {
          _currentChannel = value;

          if ( _currentChannel != null )
          {
            _currentChannel.Status = ChannelStatus.Idle;
          }

          this.OnPropertyChanged( "CurrentChannel" );
        }
      }
    }

    public ServerStatus Status
    {
      get
      {
        return _status;
      }
      set
      {
        if ( value != _status )
        {
          _status = value;

          this.OnPropertyChanged( "Status" );
        }
      }
    }

    #endregion

    #region Private Variables

    private String _address = String.Empty;

    private readonly ViewableCollection<ChannelInfo> _channels = new ViewableCollection<ChannelInfo>();

    private ChannelInfo _currentChannel = null;

    private ServerStatus _status = ServerStatus.NotConnected;

    #endregion
  }
}
